﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.pad
{
    public partial class MaterialProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<MaterialEntity> entryList = new List<MaterialEntity>();

            MaterialEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new MaterialEntity();
                    entry.JobNum = item[MaterialEntity.JOB_NUM].ToString();
                    entry.AssemblySeq = item[MaterialEntity.ASSEMBLY_SEQ].ToString();
                    entry.MtlSeq = item[MaterialEntity.MTL_SEQ].ToString();
                    entry.PartDescription = item[MaterialEntity.PART_DESCRIPTION].ToString();
                    entry.RequiredQty = Convert.ToDecimal(item[MaterialEntity.REQUIRED_QTY].ToString());
                    entry.NetWeight = Convert.ToDecimal(item[MaterialEntity.NET_WEIGHT].ToString());
                    entry.IUM = item[MaterialEntity.IUM_S].ToString();
                    entry.OnHandQty = Convert.ToDecimal(item[MaterialEntity.ON_HANDQTY].ToString());
                    entry.IssuedQty = Convert.ToDecimal(item[MaterialEntity.ISSUED_QTY].ToString());
                    entry.OldPart = item[MaterialEntity.OLD_PART].ToString();
                    entry.PartNum = item[MaterialEntity.PART_NUM].ToString();
                    entry.QtyPer = Convert.ToDecimal(item[MaterialEntity.QTY_PER].ToString());
                    entry.WarehouseCode = item[MaterialEntity.WAREHOUSE_CODE].ToString();
                    entry.OweQty = Convert.ToDecimal(item[MaterialEntity.OWE_QTY].ToString());
                   
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
